﻿$(document).ready(function () {
    $("#ul-nav li:not(.nav-header)").eq(1).addClass("active");
    page.init();
});

var page = {
    pageIndex: 0,
    pageSize: 10,
    url: "/handler/admin/user.ashx?action=",
    popU: null,

    init: function () {
        $("#ujobNumber").keyup(function () {
            $(this).val($(this).val().replace(/\D|^0/g, ''));
        }).bind("paste", function () {
            $(this).val($(this).val().replace(/\D|^0/g, ''));
        }).css("ime-mode", "disabled");

        $("#uphone").keyup(function () {
            $(this).val($(this).val().replace(/\D|^0/g, ''));
        }).bind("paste", function () {
            $(this).val($(this).val().replace(/\D|^0/g, ''));
        }).css("ime-mode", "disabled");

        $("#btnAdd").bind("click", page.add);
    },

    add: function () {
        var jobNumber = $.trim($("#ujobNumber").val());
        if ($.trim(jobNumber) == "") {
            alert("请输入工号");
            $("#ujobNumber").focus();
            return false;
        }

        var userName = $.trim($("#userName").val());
        if ($.trim(userName) == "") {
            alert("请输入姓名");
            $("#userName").focus();
            return false;
        }

        var password = $.trim($("#upassword").val());
        if ($.trim(password) == "") {
            alert("请输入初始密码");
            $("#upassword").focus();
            return false;
        }

        var gender = $("#ugender").val();
        if (gender == 0) {
            alert("请选择性别");
            $("#upassword").focus();
            return false;
        }

        var deptName = $.trim($("#udeptName").val())
        if ($.trim(deptName) == "") {
            alert("请输入所属部门");
            $("#udeptName").focus();
            return false;
        }

        var jobName = $.trim($("#ujobName").val());
        var phone = $.trim($("#uphone").val());
        var email = $.trim($("#uemail").val());

        $.post(page.url + "addUser", { jobNumber: jobNumber, userName: userName, password: password, gender: gender,
            deptName: deptName, jobName: jobName, phone: phone, email: email
        }, function (data) {
            if (data.error) {
                alert(data.error);
                return false;
            }
            alert("添加成功");
            $('.form-horizontal input').val('');
        }, "json");
    }
};

